<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            height: 3000px;
        }
        #box{
            height: 100px;
            background-color: blue;
        }
        #box1{
            height: 100px;
            background-color: blueviolet;
        }
        #box3{
            height: 100px;
            background-color: red;
        }
        #box4{
            height: 100px;
            background-color: cyan;
        }
        #box2{
            /* position: relative; */
            display: flex;
            height: 150px;
            background-color: yellow;
            justify-content: center;
            align-items: center;
        }
        #inp{
            /* position: absolute; */
            height: 30px;
            width: 500px;
            background-color: whitesmoke;
            /* border-radius: 10px 10px 10px 10px; */
            border:2px solid gray;
        }
    </style>
</head>
<body>
    <div id="box3"></div>
    <div id="box4"></div>
    <div id="box2">
        <input type="text" id="inp" >
    </div>
    <div id="box"></div>
    <div id="box1"></div>
    
    


    <script>

        window.onscroll = function(){
            if(scrollY > 295){
                inp.style.position = 'fixed'
                inp.style.top = '10px'
            }else{
                inp.style.position = ''
                inp.style.top = '15px'
            }
            console.log(scrollY);
            
        }

    </script>
</body>
</html>